<?php
namespace app\admin\controller\order;

use app\admin\BaseController;
use app\admin\model\ChargePile;
use app\admin\model\ChargingStation;
use think\App;
use think\facade\View;
use think\facade\Request;
use app\admin\model\order\YkcOrder as YkcOrderModel;

class YkcOrder extends BaseController
{
    /**
     * 列表页面
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function index()
    {
        $stationModel = new ChargingStation();
        $getList =$stationModel->getAllList(['is_delete'=>1],'id,title');
        View::assign('getList', $getList);
        return View::fetch('order/ykcOrder/index');
    }

    /**
     * 获取列表
     * @return $this
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function list(){
        [$page,$limit] = $this->getPage();
        $getData = Request::post();
        $ykcOrderModel = new YkcOrderModel();
        $backData = $ykcOrderModel->getList($getData,$page,$limit);
        $backData['code'] = 0;
        $backData['msg'] = '获取成功';
        return json()->data($backData);
    }

    /**
     * 获取详情页面
     * @return string
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    function getDetailsPage(){
        $id = Request::get('id');
        if($id){
            $ykcOrderModel = new YkcOrderModel();
            $stationModel = new ChargingStation();
            $pileModel = new ChargePile();
            $getInfo = $ykcOrderModel->getInfoById($id);
            if($getInfo){
                $statusPay = [0=>'未支付',1=>'已支付'];
                $statusList = config('add.order_status_list');
                $getInfo['pay_name'] = isset($statusPay[$getInfo['paid']]) ? $statusPay[$getInfo['paid']] : '';
                $getInfo['status_name'] = isset($statusPay[$getInfo['status']]) ? $statusPay[$getInfo['status']] : '完成';
                $getInfo['station_name'] = '';
                $getInfo['pile_number'] = '';
                if($getInfo['station_id']) $getInfo['station_name'] = $stationModel->where('id',$getInfo['station_id'])->value('title');
                if($getInfo['pile_id']) $getInfo['pile_number'] = $pileModel->where('id',$getInfo['pile_id'])->value('device_sn');
            }
        }else{
            $getInfo = [];
        }
        View::assign('info', $getInfo);
        return View::fetch('order/ykcOrder/info');
    }




}


